Skip to content

Guard shared maps in modelManager and config with locking#8

Open
phyceClaw wants to merge 1 commit into
phyce:mainfrom
phyceClaw:fix/concurrency-guards
Open

Guard shared maps in modelManager and config with locking#8
phyceClaw wants to merge 1 commit into
phyce:mainfrom
phyceClaw:fix/concurrency-guards

Conversation

@phyceClaw

Copy link
Copy Markdown

Summary

Eliminates data races on shared maps that were read without the lock while other paths mutated them under a write lock (notably reachable in server mode).

modelManager: GetEngineInstance, GetAllModels, GetAllEngines, GetModelVoices, GetInstanceCount now hold the read lock while iterating Engines/Models. restartLocalEngines no longer unlocks/relocks in the middle of a range — it collects engine IDs under one lock, then restarts.

config: Get/GetSettings/GetModelToggles/GetEngineToggles now read under the lock and return copies of escaping maps. Import now takes the write lock.

Done conservatively to avoid deadlocks (unlocked inner helpers where methods call each other).

Testing

CGO_ENABLED=1 go build ./app/... passes; go vet clean.

🤖 Generated with Claude Code

Several readers iterated manager.Engines / entry.Models / config
without holding the lock while writers mutated them under a write
lock, causing data races and potential concurrent-map-iteration
panics (notably in server mode). Add RLock to the affected readers,
return copies of maps that escape, take the write lock in Import,
and fix the unlock/relock-during-range in restartLocalEngines.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant